new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Data: 'page_services_info',
                Primary_Key: '',
                Primary_Key_Name: 'Page_Services_Title',
                isVague: true,
                page: 1,			//页数
                limit: 10,			//每页数据条数
            },
            total: 0,
            tableData: [],		//表格数据
        }
    },
    mounted() {
        this.getList(this.form)
    },
    methods: {
        onSerach() {				//查询方法
            this.form.page = 1;
            this.getList(this.form)
        },
        Add() {
            window.location.href = './Add.html'
        },
        handleSizeChange(val) {
            this.form.page = 1;
            this.form.limit = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.page = val;
            this.getList(this.form)
        },
        getList(data) {     //换页方法
            let _this = this
            $.ajax({
                type: 'POST',
                url: `${DomainName}/getTableInquiryAction?token=${$.cookie('token')}`,
                data,
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (Result) {
                    if (Result.Status == 'success') {
                        _this.tableData = Result.tableData
                        _this.total = parseInt(Result.limit)
                        
                    }
                },
                dataType: "json"
            });
        },
        Edit(Page_Services_SerialNumber) {
            sessionStorage.setItem("Page_Services_SerialNumber", Page_Services_SerialNumber)
            window.location.href = './Edit.html?Page_Services_SerialNumber=' + Page_Services_SerialNumber
        },
        Status(row) {
            const _this = this
            let obj = deepClone(row)
            obj.Page_Services_Status = obj.Page_Services_Status == '0' ? '1' : '0'
            $.ajax({
                url: DomainName + '/getEditAction?token=' + $.cookie('token'),
                type: 'POST',
                data: {
                    Data: JSON.stringify({ Modify:{page_services_info: [obj] }}),
                    Operation_Name: row.Page_Services_Status == '0' ? '禁用服务' : '启用服务'
                },
                success: function (res) {
                    if (res.Status == 'success') {
                        _this.$message({
                            type: 'success',
                            message: row.Page_Services_Status == '0' ? '禁用成功' : '启用成功'
                        });
                        _this.getList(_this.form);
                    }
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                }
            })
        },
        Delete(row) {
            const _this = this
            this.$confirm('警告！此操作将删除该服务, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                $.ajax({
                    url: DomainName + '/DeleteAction?token=' + $.cookie('token'),
                    type: 'POST',
                    data: {
                        TableName: 'page_services_info',
                        Primary_Key: row.Page_Services_SerialNumber,
                        Primary_Key_Name: 'Page_Services_SerialNumber',
                        Operation_Name: '删除服务'
                    },
                    success: function (res) {
                        if (res.Status == 'success') {
                            _this.getList(_this.form);
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                        }
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'warning',
                    message: '已取消操作'
                });
            });
        },
    },
})